﻿namespace GoodAdmin.Web.Core;

/// <summary>
/// 字典数据管理控制器
/// </summary>
[ApiDescriptionSettings("System", Tag = "字典数据管理")]
[Route("/system/dictData")]
public class DictDataController : IDynamicApiController
{
    private readonly IDictDataService _dictDataService;
    private readonly IDictTypeService _dictTypeService;

    public DictDataController(IDictDataService DictDataService,IDictTypeService dictTypeService)
    {
        _dictDataService = DictDataService;
        _dictTypeService = dictTypeService;
    }
    /// <summary>
    /// 添加字典数据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("add")]
    [DisplayName("添加字典数据")]
    public async Task Add(DictDataAddInput input)
    {
        await _dictDataService.Add(input);
    }
    /// <summary>
    /// 删除字典数据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除字典数据")]
    public async Task Delete(BaseIdInput input)
    {
        await _dictDataService.Delete(input);
    }

    /// <summary>
    /// 更新字典数据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("update")]
    [DisplayName("更新字典数据")]
    public async Task Update(DictDataUpdateInput input)
    {
        await _dictDataService.Update(input);
    }
    /// <summary>
    /// 字典数据列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("list")]
    [DisplayName("字典数据列表")]
    public async Task<List<SysDictData>> GetDictDataList()
    {
        return await _dictDataService.GetDictDataList();
    }

    /// <summary>
    /// 根据字典类型获取字典数据
    /// </summary>
    /// <param name="DictTypeId"></param>
    /// <returns></returns>
    [HttpGet("listByTypeId")]
    [DisplayName("根据字典类型获取字典数据")]
    public async Task<List<SysDictData>> GetDictDataList(long DictTypeId)
    {
        return await _dictDataService.GetDictDataList(DictTypeId);
    }
    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    [DisplayName("分页查询")]
    public async Task<SqlSugarPagedList<SysDictData>> GetDictDataPageList([FromQuery]DictDataPageInput input)
    {
        return await _dictDataService.GetDictDataPageList(input);
    }
    /// <summary>
    /// 根据字典类型获取字典数据
    /// </summary>
    /// <param name="Category"></param>
    /// <returns></returns>
    [HttpGet("listByType")]
    [DisplayName("根据字典类型获取字典数据")]
    public async Task<List<SysDictData>> GetDictDataList(string Category)
    {
        var typeId = await _dictTypeService.GetDictTypeId(Category);
        return await _dictDataService.GetDictDataList(typeId);
    }
}